﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace thienloi
{
    public partial class frmNhapDiem : Form
    {
        public frmNhapDiem()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        
        //Column3
        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (this.dataGridView1.CurrentCellAddress.X == dataGridView1.Columns[2].DisplayIndex)
            {
                TextBox txt = e.Control as TextBox;
                txt.Name = "Column3";
                if (txt != null)
                {
                    txt.KeyPress -= new KeyPressEventHandler(txt_KeyPress);
                    txt.KeyPress += new KeyPressEventHandler(txt_KeyPress);
                    txt.Validating -= new CancelEventHandler(txt_Validating);
                    txt.Validating += new CancelEventHandler(txt_Validating);
                }
            }
        }
        ////
        private void txt_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Kim tra 
            TextBox txt = sender as TextBox;
            if (txt.Name == "Column3")
            {
                 //Là các ký tự số hoặc điều khiển
                if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar) || e.KeyChar == '.')
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = true;
                }
            }
        }
        ////
        private void txt_Validating(object sender, CancelEventArgs e)
        {
            TextBox txt = sender as TextBox;
            if (txt.Name == "Column3")
            {
                try
                {
                     int i=0;
                    // int.TryParse(txt.Text, i);
                    // int.TryParse(txt.Text, i);
                }
                catch {
                    MessageBox.Show("Bạn phải nhập vào dữ liệu kiểu số.");
                }
            }
        }

        private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            dataGridView1.Rows[e.RowIndex].Cells["Column1"].Value = e.RowIndex + 1;
        }

        private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 17)
            {
                dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 2].Value = 1111;
            }
            if (e.ColumnIndex == 18)
            {
                dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value = 11111;
            }
        }
        ////
    }
}
